package cn.edu.sgu.www.mhxysy.controller.xingshi;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.xingshi.XingshiFulingDTO;
import cn.edu.sgu.www.mhxysy.entity.xingshi.XingshiFuling;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.xingshi.XingshiFulingService;
import cn.edu.sgu.www.mhxysy.vo.except.AttributeVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "星石附灵属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/xingshi_fuling", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class XingshiFulingController {

	private final XingshiFulingService xingshiFulingService;

	@Autowired
	public XingshiFulingController(XingshiFulingService xingshiFulingService) {
		this.xingshiFulingService = xingshiFulingService;
	}

	@ApiOperation("添加星石附灵属性")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(XingshiFulingDTO xingshiFulingDTO) {
		xingshiFulingService.insert(xingshiFulingDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID删除星石附灵属性")
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	public JsonResult<Void> deleteById(@RequestParam String id) {
		xingshiFulingService.deleteById(id);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过ID修改星石附灵属性")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(XingshiFulingDTO xingshiFulingDTO) {
		xingshiFulingService.updateById(xingshiFulingDTO);

		return JsonResult.success(CustomMessages.DELETE_SUCCESS);
	}

	@ApiOperation("通过星石ID查询星石附灵属性")
	@RequestMapping(value = "/selectAttributes", method = RequestMethod.GET)
	public JsonResult<List<AttributeVO>> selectAttributes(
			@ApiParam(name = "xingshiId", value = "星石ID", required = true)
			@NotBlank(message = CustomMessages.XINGSHI_ID_NOT_NULL) String xingshiId) {
		List<AttributeVO> list = xingshiFulingService.selectAttributes(xingshiId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过星石ID查询星石附灵属性")
	@RequestMapping(value = "/selectByXingshiId", method = RequestMethod.GET)
	public JsonResult<List<XingshiFuling>> selectByXingshiId(
			@ApiParam(name = "xingshiId", value = "星石ID", required = false)
			@RequestParam(required = false) String xingshiId) {
		List<XingshiFuling> list = xingshiFulingService.selectByXingshiId(xingshiId);

		return JsonResult.success(null, list);
	}

}